﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ChartTools
{
    /// <summary>
    /// 饼图
    /// </summary>
    public class Pie3D
    {
        private List<Pie3DData> datas;
        private string Function;
        private string ShowDivId;
        private string Title;
        private int Height;
        public Pie3D(List<Pie3DData> pDatas, string pFunctionName, string pShowDivId, string pTitle, int height)
        {
            datas = pDatas;
            ShowDivId = pShowDivId;
            Function = pFunctionName;
            Title = pTitle;
            this.Height = height;
        }
        private Pie3D() { }
        public override string ToString()
        {
            StringBuilder sb = new StringBuilder();
            sb.Append("<chart caption='" + Title + "' palette='2' animation='1' subCaption='' YAxisName='' showValues='1'  numberPrefix=''  formatNumberScale='0' showPercentInToolTip='1' showLabels='0' showLegend='0'>");
            foreach (Pie3DData data in datas)
            {
                //if (data.IsSelected == true)
                //{
                //    if (string.IsNullOrEmpty(data.Color))
                //    {

                //        sb.Append("<set label='" + data.Label + "' value='" + data.Value + "' isSliced='1'/>");
                //    }
                //    else
                //    {
                //        sb.Append("<set label='" + data.Label + "' value='" + data.Value + "' isSliced='1' color='" + data.Color + "' />");
                //    }
                //}
                //else
                //{
                //    if (string.IsNullOrEmpty(data.Color))
                //    {
                sb.Append("<set label='" + data.Label + "' value='" + data.Value + "' isSliced='0'/>");
                //    }
                //    else
                //    {
                //        sb.Append("<set label='" + data.Label + "' value='" + data.Value + "' isSliced='0' color='" + data.Color + "' />");
                //    }
                //}

            }
            sb.Append("<styles><definition><style type='font' name='CaptionFont' color='000000'  size='15'/></definition><application><apply toObject='caption' styles='CaptionFont' /></application></styles></chart>");
            string datastring = sb.ToString();
            sb = new StringBuilder();
            sb.Append("<script type='text/javascript'>");
            sb.Append("function " + Function + "(){");
            sb.Append("var chart = new FusionCharts('/Content/FusionCharts/Pie3D.swf', 'ChartId', '100%', '" + (Height + (Height * 0.2)) + "', '0', '0');");
            sb.Append("chart.setXMLData(\"" + datastring + "\");");
            sb.Append("chart.render('" + ShowDivId + "');");
            sb.Append("}");
            sb.Append("</script>");
            return sb.ToString();
        }
    }

    public class Pie3DData
    {
        public string Label { get; set; }

        public double Value { get; set; }

        public bool IsSelected { get; set; }

        public string Color { get; set; }
    }
}
